package com.asa.voice.mp3.asa.decoder;

public class Layer1 extends Layer123 {
	  Header header;
	  
	  BitStream bs;
	  
	  float[] factor;
	  
	  byte[][] allocation;
	  
	  byte[][] scalefactor;
	  
	  float[][] syin;
	  
	  public Layer1(Header paramHeader, IAudio paramIAudio) {
	    super(paramHeader, paramIAudio);
	    this.header = paramHeader;
	    this.bs = new BitStream(4096, 512);
	    this.allocation = new byte[2][32];
	    this.scalefactor = new byte[2][32];
	    this.syin = new float[2][32];
	    this.factor = Layer2.factor;
	  }
	  
	  private float requantization(int paramInt1, int paramInt2, int paramInt3) {
	    int i = this.bs.getBits17(paramInt3);
	    int j = 1 << paramInt3;
	    float f = 2.0F * i / j - 1.0F;
	    f += (float)Math.pow(2.0D, (1 - paramInt3));
	    f *= (j / (j - 1));
	    f *= this.factor[this.scalefactor[paramInt1][paramInt2]];
	    return f;
	  }
	  
	  public int decodeFrame(byte[] paramArrayOfbyte, int paramInt) {
	    int i = this.header.getChannels();
	    int b3 = (this.header.getMode() == 1) ? ((this.header.getModeExtension() + 1) * 4) : 32;
	    int j = this.header.getMainDataSize();
	    if (this.bs.append(paramArrayOfbyte, paramInt, j) < j)
	      return -1; 
	    paramInt += j;
	    int k = this.bs.getBytePos();
	    byte b1;
	    for (b1 = 0; b1 < b3; b1++) {
	      for (byte b = 0; b < i; b++) {
	        int n = this.bs.getBits9(4);
	        if (n == 15)
	          return -2; 
	        this.allocation[b][b1] = (byte)((n != 0) ? (n + 1) : 0);
	      } 
	    } 
	    for (b1 = (byte) b3; b1 < 32; b1++) {
	      int n = this.bs.getBits9(4);
	      if (n == 15)
	        return -2; 
	      this.allocation[0][b1] = (byte)((n != 0) ? (n + 1) : 0);
	    } 
	    for (b1 = 0; b1 < 32; b1++) {
	      for (byte b = 0; b < i; b++) {
	        if (this.allocation[b][b1] != 0)
	          this.scalefactor[b][b1] = (byte)this.bs.getBits9(6); 
	      } 
	    } 
	    for (byte b2 = 0; b2 < 12; b2++) {
	      for (b1 = 0; b1 < b3; b1++) {
	        for (byte b4 = 0; b4 < i; b4++) {
	          byte b5 = this.allocation[b4][b1];
	          if (b5 == 0) {
	            this.syin[b4][b1] = 0.0F;
	          } else {
	            this.syin[b4][b1] = requantization(b4, b1, b5);
	          } 
	        } 
	      } 
	      for (b1 = (byte) b3; b1 < 32; b1++) {
	        byte b4;
	        if ((b4 = this.allocation[0][b1]) != 0) {
	          for (byte b5 = 0; b5 < i; b5++)
	            this.syin[b5][b1] = requantization(b5, b1, b4); 
	        } else {
	          for (byte b5 = 0; b5 < i; b5++)
	            this.syin[b5][b1] = 0.0F; 
	        } 
	      } 
	      for (byte b = 0; b < i; b++)
	        this.filter.synthesisSubBand(this.syin[b], b); 
	    } 
	    int m = j + k - this.bs.getBytePos();
	    this.bs.skipBytes(m);
	    outputAudio();
	    return paramInt;
	  }
	}
